import { statusType, statusEnum } from '../type';

class Modal {
  status: statusType;
  constructor(status: statusType) {
    this.status = status;
  }
  get className() {
    let classStr = 'modal';
    return classStr + ' ' + this.status;
  }
}

class SuccessModal extends Modal {
  constructor() {
    super(statusEnum[0] as statusType);
  }
}
class WarnModal extends Modal {
  constructor() {
    super(statusEnum[1] as statusType);
  }
}
class ErrorModal extends Modal {
  constructor() {
    super(statusEnum[2] as statusType);
  }
}

class ModalFactory {
  dom: any;
  constructor(dom: any) {
    this.dom = dom;
  }
  createModal(status: statusType) {
    const dom = this.dom;
    let modal = null;
    switch (statusEnum[status]) {
      case statusEnum.success:
        modal = new SuccessModal();
        break;
      case statusEnum.warn:
        modal = new WarnModal();
        break;
      case statusEnum.error:
        modal = new ErrorModal();
        break;
      default:
        break;
    }
    const m = dom.querySelector('.modal');
    const modalDom = m || document.createElement('div');
    modalDom.className = modal?.className;
    dom.appendChild(modalDom);
  }
}
export default ModalFactory;
